﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class Create
    {
        /// <summary>
        /// 添加模型
        /// </summary>
        public static int CreateModel(Models.Model model)
        {
            string sql = string.Format("insert into tb_model(Name,AdminDir,WebDir,TableName,Remark) values(@Name,@AdminDir,@WebDir,@TableName,@Remark)");
            SqlParameter[] parameters ={
                                             new SqlParameter("Name",SqlDbType.NVarChar,50),
                                            new SqlParameter("AdminDir",SqlDbType.NVarChar,50),
                                            new SqlParameter("WebDir",SqlDbType.NVarChar,50),
                                            new SqlParameter("TableName",SqlDbType.NVarChar,50),
                                            new SqlParameter("Remark",SqlDbType.NVarChar,500)
                                      };
            parameters[0].Value=model.Name;
             parameters[1].Value=model.AdminDir;
             parameters[2].Value=model.WebDir;
             parameters[3].Value=model.TableName;
             parameters[4].Value=model.Remark;

             Utility.SQLHelper db = new Utility.SQLHelper();
             return db.ExecuteNonQuery(sql, parameters, CommandType.Text);
        }
        /// <summary>
        /// 添加日志
        /// </summary>
        /// <param name="log"></param>
        /// <returns></returns>
        public static int CreateLogRecord(Models.Log log)
        {
            string sql = string.Format("insert into tb_log(UserName,UserIP,Time,Action) values(@UserName,@UserIP,@Time,@Action)");
            SqlParameter[] parameters = {
                                            new SqlParameter("UserName", SqlDbType.NVarChar, 50),
                                            new SqlParameter("UserIP", SqlDbType.NVarChar, 50),
                                            new SqlParameter("Time", SqlDbType.DateTime),
                                            new SqlParameter("Action", SqlDbType.NVarChar, 500)
                                        };
            parameters[0].Value = log.UserName;
            parameters[1].Value = log.UserIP;
            parameters[2].Value = log.Time;
            parameters[3].Value = log.Action;

            Utility.SQLHelper db = new Utility.SQLHelper();
            return db.ExecuteNonQuery(sql, parameters, CommandType.Text);
        }
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static int CreateUser(Models.User user)
        {
            string sql = string.Format("insert into tb_user(Name,Password,RoleID,UserEnabled) values(@Name,@Password,@RoleID,@UserEnabled)");
            SqlParameter[] parameters = {
                                            new SqlParameter("Name", SqlDbType.NVarChar, 50),
                                            new SqlParameter("Password", SqlDbType.NVarChar, 255),
                                            new SqlParameter("RoleID", SqlDbType.Int),
                                            new SqlParameter("UserEnabled", SqlDbType.Bit)
                                        };
            parameters[0].Value = user.Name;
            parameters[1].Value = user.Password;
            parameters[2].Value = user.RoleID;
            parameters[3].Value = user.UserEnabled;

            Utility.SQLHelper db = new Utility.SQLHelper();
            return db.ExecuteNonQuery(sql, parameters, CommandType.Text);
        }
        /// <summary>
        /// 添加小黄侠
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static int CreateTeam(Models.Team team)
        {
            string sql = string.Format("insert into tb_team(xuehao,name,password,author,remark) values(@xuehao,@name,@password,@author,@remark)");
            SqlParameter[] parameters = {
                                            new SqlParameter("xuehao", SqlDbType.NVarChar, 50),
                                             new SqlParameter("name", SqlDbType.NVarChar, 50),
                                              new SqlParameter("password", SqlDbType.NVarChar, 50),
                                               new SqlParameter("author", SqlDbType.NVarChar, 50),
                                                new SqlParameter("remark", SqlDbType.NVarChar, int.MaxValue),
                                            
                                          
                                        };
            parameters[0].Value = team.xuehao;
            parameters[1].Value = team.name;
            parameters[2].Value = team.password;
            parameters[3].Value = team.author;
            parameters[4].Value = team.remark;
            Utility.SQLHelper db = new Utility.SQLHelper();
            return db.ExecuteNonQuery(sql, parameters, CommandType.Text);
        }
        /// <summary>
        /// 添加小黄车
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public static int Createofo(Models.ofo ofo)
        {
            string sql = string.Format("insert into tb_ofo(chepai,password,author,remark) values(@chepai,@password,@author,@remark)");
            SqlParameter[] parameters = {
                                            new SqlParameter("chepai", SqlDbType.NVarChar, 50),                                    
                                              new SqlParameter("password", SqlDbType.NVarChar, 50),
                                               new SqlParameter("author", SqlDbType.NVarChar, 50),
                                                new SqlParameter("remark", SqlDbType.NVarChar, int.MaxValue),
                                            
                                          
                                        };
            parameters[0].Value = ofo.chepai;
            parameters[1].Value = ofo.password;
            parameters[2].Value = ofo.author;
            parameters[3].Value = ofo.remark;
            Utility.SQLHelper db = new Utility.SQLHelper();
            return db.ExecuteNonQuery(sql, parameters, CommandType.Text);
        }
        /// <summary>
        /// 添加角色
        /// </summary>
        public static int CreateRole(Models.Role role)
        {
            string sql = string.Format("insert into tb_role(Name,RoleInfoModelID,RoleEnabled,IsAdmin,ModelAdmin,UserAdmin,RoleAdmin,LogAdmin,SystemAdmin,ColumnAdmin,FileAdmin,ContentAdmin) values(@Name,@RoleInfoModelID,@RoleEnabled,@IsAdmin,@ModelAdmin,@UserAdmin,@RoleAdmin,@LogAdmin,@SystemAdmin,@ColumnAdmin,@FileAdmin,@ContentAdmin)");
            SqlParameter[] parameters = {
                                            new SqlParameter("Name", SqlDbType.NVarChar, 50),
                                            new SqlParameter("RoleInfoModelID", SqlDbType.Int),
                                             new SqlParameter("RoleEnabled", SqlDbType.Bit),
                                            new SqlParameter("IsAdmin", SqlDbType.Bit),
                                            new SqlParameter("ModelAdmin", SqlDbType.Bit),
                                             new SqlParameter("UserAdmin", SqlDbType.Bit),
                                            new SqlParameter("RoleAdmin", SqlDbType.Bit),
                                             new SqlParameter("LogAdmin", SqlDbType.Bit),
                                              new SqlParameter("SystemAdmin", SqlDbType.Bit),
                                            new SqlParameter("ColumnAdmin", SqlDbType.Bit),
                                                new SqlParameter("FileAdmin", SqlDbType.Bit),
                                            new SqlParameter("ContentAdmin", SqlDbType.NVarChar, int.MaxValue),
                                           
                                        
                                           
                                           
                                           
                                        };
            parameters[0].Value = role.Name;
            parameters[1].Value = role.RoleInfoModelID;
            parameters[2].Value = role.RoleEnabled;
            parameters[3].Value = role.IsAdmin;
            parameters[4].Value = role.ModelAdmin;       
            parameters[5].Value = role.UserAdmin;
            parameters[6].Value = role.RoleAdmin;          
            parameters[7].Value = role.LogAdmin;
            parameters[8].Value = role.SystemAdmin;
            parameters[9].Value = role.ColumnAdmin;
            parameters[10].Value = role.FileAdmin;
            parameters[11].Value = role.ContentAdmin;
           

            Utility.SQLHelper db = new Utility.SQLHelper();
            return db.ExecuteNonQuery(sql, parameters, CommandType.Text);
        }
        /// <summary>
        /// 插入新栏目
        /// </summary>
        public static int InsertColumn(Models.Column column)
        {
            string sql = string.Format("insert into tb_column(Name,ParentID,ModelID,ColumnLogo,Remark) values(@Name,@ParentID,@ModelID,@ColumnLogo,@Remark)");
            SqlParameter[] parameters = {
                                            new SqlParameter("Name", SqlDbType.NVarChar, 50),
                                            new SqlParameter("ParentID", SqlDbType.Int),
                                            new SqlParameter("ModelID", SqlDbType.Int),
                                             new SqlParameter("ColumnLogo", SqlDbType.NVarChar, 50),
                                            new SqlParameter("Remark", SqlDbType.NVarChar, 500)
                                        };
            parameters[0].Value = column.Name;
            parameters[1].Value = column.ParentID;
            parameters[2].Value = column.ModelID;
            parameters[3].Value = column.ColumnLogo;
            parameters[4].Value = column.Remark;

            Utility.SQLHelper db = new Utility.SQLHelper();
            return db.ExecuteNonQuery(sql, parameters, CommandType.Text);
        }
        /// <summary>
        /// 插入新文章模型内容
        /// </summary>
        public static int InsertArticle(Models.ModelArticle article)
        {
            string sql = string.Format("insert into tb_content_article(FirstEditor,LastEditor,ColumnID,Title,Content,Source,UpdateDate,Status) values(@FirstEditor,@LastEditor,@ColumnID,@Title,@Content,@Source,@UpdateDate,@Status)");
            SqlParameter[] parameters = {
                                            new SqlParameter("FirstEditor", SqlDbType.NVarChar, 50),
                                            new SqlParameter("LastEditor", SqlDbType.NVarChar, 50),                                            
                                            new SqlParameter("ColumnID", SqlDbType.Int),
                                            new SqlParameter("Title", SqlDbType.NVarChar, 100),
                                            new SqlParameter("Content", SqlDbType.NVarChar,int.MaxValue),
                                            new SqlParameter("Source", SqlDbType.NVarChar, 100),
                                            new SqlParameter("UpdateDate", SqlDbType.DateTime),
                                            new SqlParameter("Status", SqlDbType.Bit)
                                        };
            parameters[0].Value = article.FirstEditor;
            parameters[1].Value = article.LastEditor;
            parameters[2].Value = article.ColumnID;
            parameters[3].Value = article.Title;
            parameters[4].Value = article.Content;
            parameters[5].Value = article.Source;
            parameters[6].Value = article.UpdateDate;
            parameters[7].Value = article.Status;

            Utility.SQLHelper db = new Utility.SQLHelper();
            return db.ExecuteNonQuery(sql, parameters, CommandType.Text);
        }
        /// <summary>
        /// 插入新单页模型内容
        /// </summary>
        public static int InsertContent(Models.ModelContent content)
        {
            string sql = string.Format("insert into tb_content(FirstEditor,LastEditor,ColumnID,Title,Content,UpdateDate) values(@FirstEditor,@LastEditor,@ColumnID,@Title,@Content,@UpdateDate)");
            SqlParameter[] parameters = {
                                            new SqlParameter("FirstEditor", SqlDbType.NVarChar, 50),
                                            new SqlParameter("LastEditor", SqlDbType.NVarChar, 50),                                            
                                            new SqlParameter("ColumnID", SqlDbType.Int),
                                            new SqlParameter("Title", SqlDbType.NVarChar, 50),
                                            new SqlParameter("Content", SqlDbType.NVarChar,int.MaxValue),
                                            new SqlParameter("UpdateDate", SqlDbType.DateTime)
                                        };
            parameters[0].Value = content.FirstEditor;
            parameters[1].Value = content.LastEditor;
            parameters[2].Value = content.ColumnID;
            parameters[3].Value = content.Title;
            parameters[4].Value = content.Content;
            parameters[5].Value = content.UpdateDate;

            Utility.SQLHelper db = new Utility.SQLHelper();
            return db.ExecuteNonQuery(sql, parameters, CommandType.Text);
        }
        /// <summary>
        /// 插入新滑动图片模型内容
        /// </summary>
        public static int InsertSlider(Models.ModelSlider slider)
        {
            string sql = string.Format("insert into tb_content_slider(FirstEditor,LastEditor,ColumnID,Title,UpdateDate,PictureAddress,ArticleAddress,Remark) values(@FirstEditor,@LastEditor,@ColumnID,@Title,@UpdateDate,@PictureAddress,@ArticleAddress,@Remark)");
            SqlParameter[] parameters = {
                                            new SqlParameter("FirstEditor", SqlDbType.NVarChar, 50),
                                            new SqlParameter("LastEditor", SqlDbType.NVarChar, 50),                                            
                                            new SqlParameter("ColumnID", SqlDbType.Int),
                                            new SqlParameter("Title", SqlDbType.NVarChar, 50),
                                            new SqlParameter("UpdateDate", SqlDbType.DateTime),                                       
                                            new SqlParameter("PictureAddress", SqlDbType.NVarChar, 100),
                                            new SqlParameter("ArticleAddress", SqlDbType.NVarChar, 100),
                                            new SqlParameter("Remark", SqlDbType.NVarChar, 500)
                                        };
            parameters[0].Value = slider.FirstEditor;
            parameters[1].Value = slider.LastEditor;
            parameters[2].Value = slider.ColumnID;
            parameters[3].Value = slider.Title;
            parameters[4].Value = slider.UpdateDate;
            parameters[5].Value = slider.PictureAddress;
            parameters[6].Value = slider.ArticleAddress;
            parameters[7].Value = slider.Remark;

            Utility.SQLHelper db = new Utility.SQLHelper();
            return db.ExecuteNonQuery(sql, parameters, CommandType.Text);
        }
        /// <summary>
        /// 插入外链模型内容
        /// </summary>
        public static int InsertLink(Models.ModelLink link)
        {
            string sql = string.Format("insert into tb_content_link(FirstEditor,LastEditor,ColumnID,WebUrl,UpdateDate,WebName,WebLogo) values(@FirstEditor,@LastEditor,@ColumnID,@WebUrl,@UpdateDate,@WebName,@WebLogo)");
            SqlParameter[] parameters = {
                                            new SqlParameter("FirstEditor", SqlDbType.NVarChar, 50),
                                            new SqlParameter("LastEditor", SqlDbType.NVarChar, 50),                                            
                                            new SqlParameter("ColumnID", SqlDbType.Int),
                                            new SqlParameter("WebUrl", SqlDbType.NVarChar, 50),
                                            new SqlParameter("UpdateDate", SqlDbType.DateTime),                                       
                                            new SqlParameter("WebName", SqlDbType.NVarChar, 50),
                                            new SqlParameter("WebLogo", SqlDbType.NVarChar, 50),
                                           
                                        };
            parameters[0].Value = link.FirstEditor;
            parameters[1].Value = link.LastEditor;
            parameters[2].Value = link.ColumnID;
            parameters[3].Value = link.WebUrl;
            parameters[4].Value = link.UpdateDate;
            parameters[5].Value = link.WebName;
            parameters[6].Value = link.WebLogo;
 

            Utility.SQLHelper db = new Utility.SQLHelper();
            return db.ExecuteNonQuery(sql, parameters, CommandType.Text);
        }
        /// <summary>
        /// 插入办公文件模型内容
        /// </summary>
        public static int InsertOfficeFile(Models.ModelOfficeFile file)
        {
            string sql = string.Format("insert into tb_content_officefile(ColumnID,FileName,FileEditor,FileType,FileSize,FileUrl,UploadTime,UploadSource) values(@ColumnID,@FileName,@FileEditor,@FileType,@FileSize,@FileUrl,@UploadTime,@UploadSource)");
            SqlParameter[] parameters = {
                                            new SqlParameter("ColumnID", SqlDbType.Int, 50),
                                            new SqlParameter("FileName", SqlDbType.NVarChar, 50),                                            
                                            new SqlParameter("FileEditor", SqlDbType.NVarChar,50),
                                            new SqlParameter("FileType", SqlDbType.NVarChar,50),
                                            new SqlParameter("FileSize", SqlDbType.NVarChar),                                       
                                            new SqlParameter("FileUrl", SqlDbType.NVarChar, 50),
                                            new SqlParameter("UploadTime", SqlDbType.DateTime, 50),
                                            new SqlParameter("UploadSource", SqlDbType.NVarChar, 50),
                                           
                                        };
            parameters[0].Value = file.ColumnID;
            parameters[1].Value = file.FileName;
            parameters[2].Value = file.FileEditor;
            parameters[3].Value = file.FileType;
            parameters[4].Value = file.FileSize;
            parameters[5].Value = file.FileUrl;
            parameters[6].Value = file.UploadTime;
            parameters[7].Value = file.UploadSource;


            Utility.SQLHelper db = new Utility.SQLHelper();
            return db.ExecuteNonQuery(sql, parameters, CommandType.Text);
        }
    }
}
